package com.tangbue.springcloud.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.tangbue.springcloud.domain.CommonResult;
import com.tangbue.springcloud.service.AccountService;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.math.BigDecimal;

@RestController
public class AccountController {

    @Resource
    AccountService accountService;

    /**
     * 扣减账户余额
     */
    @RequestMapping("/account/decrease/{id}")
    @SentinelResource(value = "decrease",fallback = "handlerFallback") //fallback只负责业务异常
    public CommonResult decrease(@PathVariable Long id){
        int i = 1/0;
        return new CommonResult(200,"扣减账户余额成功！");
    }

    //本例是fallback
    public CommonResult handlerFallback(@PathVariable Long id, Throwable e) {
        return new CommonResult<>(444,"兜底异常handlerFallback,exception内容  ");
    }
}
